//
//  BBMeshView.h
//  BBTouch
//
//  Created by ben smith on 8/14/08.
//  This file is part of BBTouch.
//
//  BBTouch is free software: you can redistribute it and/or modify
//  it under the terms of the GNU Lesser General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.

//  BBTouch is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Lesser General Public License for more details.

//  You should have received a copy of the GNU Lesser General Public License
//  along with BBTouch.  If not, see <http://www.gnu.org/licenses/>.
// 
//  Copyright 2008 Ben Britten Smith ben@benbritten.com .
//

#import <Cocoa/Cocoa.h>

// a view that displayes a mesh that can be manipulated

@class BBDistortionMesh;
@class BBIndexedVertex;

@interface BBMeshView : NSView {
	BBDistortionMesh * mesh;
	BBIndexedVertex * draggingVertex;
	NSRect absoluteMeshContainingRect; // this is the outer rectangle for the mesh to be scaled into, it will be the raw camera size for the camera
																		// and the screen rect for the projection
	BOOL isFocus;
	NSInteger modFlags; // holds the keyboard modification flags
	BOOL mouseDragging;
	float scaleX,scaleY;
	NSInteger scaleHandle;
	NSMutableArray * scaleRects;
	NSPoint mousePointInView;
	NSPoint lastMousePointInView;
}

@property (retain) BBDistortionMesh * mesh;
@property (assign) NSRect absoluteMeshContainingRect;
@property (assign) float scaleX;
@property (assign) float scaleY;

- (BBIndexedVertex*)vertextAtPoint:(NSPoint)p;
- (BOOL)acceptsFirstResponder;
- (BOOL)becomeFirstResponder;
- (BOOL)canBecomeKeyView;
- (BOOL)resignFirstResponder;
- (BOOL)showMesh;
- (IBAction)keyDown:(NSEvent*)theEvent;
- (NSPoint)scale:(NSPoint)p;
- (NSRect)handleAtPoint:(NSPoint)p;
- (NSRect)scaledMeshBounds;
- (id)initWithFrame:(NSRect)frame ;
- (void)calculateScaleRects;
- (void)dragRotate:(NSEvent *)theEvent;
- (void)dragScale:(NSEvent *)theEvent;
- (void)drawRect:(NSRect)rect;
- (void)drawScalingRects;
- (void)drawVertexAtPoint:(NSPoint)p;
- (void)drawVertices;
- (void)flagsChanged:(NSEvent *)theEvent;
- (void)mouseDown:(NSEvent*)theEvent;
- (void)mouseDragged:(NSEvent*)theEvent;
- (void)mouseUp:(NSEvent*)theEvent;
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context;
- (void)resetCursorRects;
- (void)setupMesh;

// 25 methods


@end
